package com.b2c.product.config;

import com.b2c.product.handler.JwtTokenInterceptor;
import converter.BaseToEnumConverterFactory;
import converter.IntegerToEnumCoverterFactory;
import converter.StringToEnumConverterFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    JwtTokenInterceptor jwtTokenInterceptor;

    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenInterceptor).addPathPatterns("/admin");
    }

    /**
     * 添加类型转换器
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        log.info("类型转换器注册。。。。");
        registry.addConverterFactory(new BaseToEnumConverterFactory());
        registry.addConverterFactory(new IntegerToEnumCoverterFactory());
        registry.addConverterFactory(new StringToEnumConverterFactory());
    }
}
